<template>
    <div>
        个人主页
        <share :isshare="isshare"></share>
        <Bottom :baseText="baseText"></Bottom>
    </div>
</template>
<script>
import { MessageBox } from "mint-ui";
import request from "@/utils/request";
import wx from "weixin-js-sdk";
import * as config from "./config";
import Cookies from "js-cookie";
import Share from "./components/Share";
import Bottom from "@/components/common/Bottom";
import { Swipe, SwipeItem } from 'mint-ui';
// Vue.component(Swipe.name, Swipe);
// Vue.component(SwipeItem.name, SwipeItem);
export default {
    // 引入组件
    components : {
        share: Share,
        Bottom: Bottom,
    },
    data(){
        return {
            openid: Cookies.get("openid"),
            userInfo: null, //用户信息
            receiveSpreadInfo: {
                channel: 0, //渠道
                fuid: "", //传播者的openid
                ouid: "" //销售或渠道的openid
            },
            prizeList:[
                {
                    img:'http://thirdwx.qlogo.cn/mmopen/MKSUPLNLibJtwJPubIAfJCmibWeg9zvMZeWZJesBBaoibG7Viac4LT18rJ47icDP30hia4MHiaMJg4Oic4m96mfXNVpYrONMSg1cd9Ah/132'
                },
                {
                    img:'http://thirdwx.qlogo.cn/mmopen/dibCvqHg4WndblR0t0hXXia65bqnkFAM83RqRJjHpk578FxPAROEWlp7B4TtE8jFJARZZ8XO9ZD92BArns3VYvicg/132'
                },
                {
                    img:'http://thirdwx.qlogo.cn/mmopen/dibCvqHg4WndcMHgEPxMcVoj3wIvkdagneqzTKrpcgItLfvMbfjWWflXiatOEDBc4qM9Vk6mtEXnZicJ5icyvFW1oFhdk2SNZaibc/132'
                }
            ],
            isshare: false, //是否开启分享 也用于从别的页面返回回来展示分享
            baseText: config.BASE_TEXT, //页脚文本
        }
    },
    methods:{
        // 直接跳转本项目的其他链接
        gotoUrl(page) {
        // 带上本页面的传播信息
        let url =
            location.protocol +
            "//" +
            location.host +
            this.global.GLOBAL_BASE_PATH +
            "/";
        let fullPathNoShare = this.$route.fullPath;
        fullPathNoShare = fullPathNoShare.replace("?isshare=1", "");
        fullPathNoShare = fullPathNoShare.replace("&isshare=1", "");
        if (fullPathNoShare.indexOf("?") > -1) {
            url += page + "?" + fullPathNoShare.split("?")[1];
        } else {
            url += page;
        }
        location.href = url;
        },
        // 通过路由方式跳转本项目的其他链接(跳转到无需授权的)
        pushUrl(page) {
        // 带上本页面的传播信息
        let url = "";
        let fullPathNoShare = this.$route.fullPath;
        fullPathNoShare = fullPathNoShare.replace("?isshare=1", "");
        fullPathNoShare = fullPathNoShare.replace("&isshare=1", "");
        if (fullPathNoShare.indexOf("?") > -1) {
            url = page + "?" + fullPathNoShare.split("?")[1];
        } else {
            url = page;
        }
        this.$router.push("/" + url);
        },
        /**
         * 初始化
         * 1、设置传播传播信息
         * 2、获取用户信息
         * 3、设置分享信息
         */
        init() {
            console.log(2134)
        let that = this;
        // 设置传播信息
        if (this.$route.query.channel)
            this.receiveSpreadInfo.channel = this.$route.query.channel;
        if (this.$route.query.fuid)
            this.receiveSpreadInfo.fuid = this.$route.query.fuid;
        if (this.$route.query.ouid)
            this.receiveSpreadInfo.ouid = this.$route.query.ouid;
        if (this.$route.query.isshare) that.isshare = true;
        config.getUserInfo().then(function(userInfo) {
            that.userInfo = userInfo;
            // 设置分享 标题 链接 回调
            let shareObj = {
            title: "",
            link: ""
            };
            if (
            that.userInfo &&
            that.userInfo.user &&
            that.userInfo.user.nickname
            ) {
            shareObj.title = `${
                that.userInfo.user.nickname
            }邀请你跟我一起读语音赢奖品，读出你的“国际范儿”`;
            }

            if (that.userInfo.salerOrAgent) {
            // 是销售或者渠道,更新ouid
            shareObj.link = `${config.SHARE_LINK}?channel=${
                that.receiveSpreadInfo.channel
            }&fuid=${that.openid}&ouid=${that.openid}`;
            } else {
            shareObj.link = `${config.SHARE_LINK}?channel=${
                that.receiveSpreadInfo.channel
            }&fuid=${that.openid}${
                that.receiveSpreadInfo.ouid
                ? "&ouid=" + that.receiveSpreadInfo.ouid
                : ""
            }`;
            }
            config.initShare(shareObj);
            that.global.SHARE_CALLBACK_OK = function(type) {
            that.shareCallBack();
            };
        });
        }
    },
    mounted(){

    },
    created(){
        this.init()
    }
}
</script>
<style lang="stylus" scoped>

</style>
